package com.xyy.saas.payment.cores.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

/**
 * 京东支付 签约绑卡状态
 */
public enum JDPayContractStatusEnum {

    PROC(1, "签约中"),
    SUCC(2, "绑定"),
    REMO(3, "解绑"),
    FAIL(4, "绑卡失败");

    private int code;
    private String desc;

    private static Map<Integer,JDPayContractStatusEnum> code2Enum;

    static {
        code2Enum = Arrays.asList(values()).stream().collect(Collectors.toMap(JDPayContractStatusEnum::getCode, UnaryOperator.identity()));
    }

    JDPayContractStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static JDPayContractStatusEnum getEnum(int code){
        return code2Enum.get(code);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * 转换京东签约状态
     */
    public static int transJDPayContractStatus(String status) {
        if ("S".equals(status) || "SUCC".equals(status)) {
            return JDPayContractStatusEnum.SUCC.getCode();
        }
        if ("F".equals(status) || "FAIL".equals(status)) {
            return JDPayContractStatusEnum.FAIL.getCode();
        }
        if ("U".equals(status) || "PROC".equals(status)) {
            return JDPayContractStatusEnum.PROC.getCode();
        }
        if ("REMO".equals(status)) {
            return JDPayContractStatusEnum.REMO.getCode();
        }
        return JDPayContractStatusEnum.PROC.getCode();
    }

}
